package objects.info;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import actions.UpdateHosts;

import filesystem.FileSystem;
import gui.filetree.TreeUtils;

import objects.data.ClusterData;
import objects.data.WorkPacket;



public class UserInfo {
	public List<WorkPacket> workPacketList;
	public List<ClusterData> cinfo;
	public Map<String,WorkPacket> workPacketMap;
	public FileSystem fs;

	
	public UserInfo(List<ClusterData> cinfo, List<WorkPacket> wpl)
	{
		this.cinfo = cinfo;
		this.workPacketMap = new HashMap<String,WorkPacket>();
		this.workPacketList = wpl;
		for(WorkPacket wp : wpl) {
			workPacketMap.put(wp.uniqueId, wp);
		}
	}
	
	public int getClusterId(String cluster) {
		String lhost = cluster.split("@")[0];
		String host = cluster.split("@")[1];
		for(ClusterData data : cinfo) {
			if(data.hostname.equals(host) && data.local_hostname.equals(lhost)) {
				return data.db_id;
			}
		}
		return -1;
	}
	
	public void setFileSystem(String data) {
		fs = FileSystem.fromJson(data);
		TreeUtils.createFromFileSystem(fs);
	}
}
